package 面试经典150题.数组;

import java.util.Arrays;

/**
 * @author tmh
 * @date 2024/4/4 16:44
 * @description
 */
public class T27移除元素 {
    public static void main(String[] args) {
        int[] array = new int[]{3, 2, 2, 3};
        int val = 3;
        int i = removeElement(array, val);
        System.out.println(i);
        System.out.println(Arrays.toString(array));
    }

    public static int removeElement(int[] nums, int val) {
        int index = 0;
        for (int x : nums) {
            if (x != val) {
                nums[index++] = x;
            }
        }
        return index;
    }
}
